﻿using LuckyShell.ShellOrders;
using LuckyShell.ShellValues;

namespace LuckyShell.Commands;

public class TypeCommand(List<ShellValue> values) : Command(values)
{
    public override object Run(ref VariateManager manager)
    {
        switch (Values.Count)
        {
            case 1:
                var value = Values[0].GetValue(ref manager);
                var type = Api.ObjToValueType(value);
                if (string.IsNullOrEmpty(type)) throw new Exception("Value is NOT Type");
                Console.WriteLine(type);
                break;
            case 2:
                var value2 = Values[0].GetValue(ref manager);
                var bObj = Values[1].GetValue(ref manager);
                if (bObj is not bool b) throw new Exception("Second Value is Not Bool");
                var type2 = Api.ObjToValueType(value2);
                if (b)
                {
                    if (string.IsNullOrEmpty(type2)) throw new Exception("Value is NOT Type");
                    return type2;
                }
                if (string.IsNullOrEmpty(type2)) throw new Exception("Value is NOT Type");
                Console.WriteLine(type2);
                break;
        }

        return new VoidValue();
    }
}